/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    vertex_surface_light_omni.h
 * Desc:    Water surface light omni shader
 * Version: 1.12
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

/******************************************************************************\
*
* OpenGL
*
\******************************************************************************/

#ifdef OPENGL
	
	#ifndef VERTEX_SURFACE_LIGHT_OMNI
		#define VERTEX_SURFACE_LIGHT_OMNI
		
		uniform float4 normal_0_transform;
		uniform float4 normal_1_transform;
		uniform float4 normal_2_transform;
		uniform float4 normal_3_transform;
		uniform float4 foam_0_transform;
		uniform float4 foam_1_transform;
		uniform float4 caps_0_transform;
		uniform float4 caps_1_transform;
		
	#else
		
		gl_Position = getPosition(vertex);
		
		s_texcoord_0 = float4(texcoord,0.0f,0.0f);
		
		s_texcoord_1.xyz = normal;
		
		s_texcoord_2 = direction;
		
		s_texcoord_3.xyz = getOmniRadius(s_light_position - vertex.xyz) * s_light_iradius.w;
		s_texcoord_3.w = s_light_iradius.w * s_light_iradius.w;
		
		s_texcoord_4.xyz = -vertex.xyz;
		
		s_texcoord_5.xyz = mul3(vertex.xyz - s_light_position,s_light_transform);
		
		#ifdef SHADOW
			float3 shadow_direction = mul3(s_imodelview,vertex.xyz - s_light_shadow_offset);
			s_texcoord_6.xyz = shadow_direction * s_light_shadow_depth_range.x;
			s_texcoord_6.w = s_light_shadow_depth_range.y;
		#endif
		
		s_texcoord_7.xy = texcoord * normal_0_transform.xy + normal_0_transform.zw;
		s_texcoord_7.zw = texcoord * normal_1_transform.xy + normal_1_transform.zw;
		s_texcoord_8.xy = texcoord * normal_2_transform.xy + normal_2_transform.zw;
		s_texcoord_8.zw = texcoord * normal_3_transform.xy + normal_3_transform.zw;
		
		#ifdef FOAM
			s_texcoord_9.xy = texcoord * foam_0_transform.xy + foam_0_transform.zw;
			s_texcoord_9.zw = texcoord * foam_1_transform.xy + foam_1_transform.zw;
		#endif
		
		#ifdef CAPS
			s_texcoord_10.xy = texcoord * caps_0_transform.xy + caps_0_transform.zw;
			s_texcoord_10.zw = texcoord * caps_1_transform.xy + caps_1_transform.zw;
		#endif
		
	#endif
	
/******************************************************************************\
*
* Direct3D11
*
\******************************************************************************/

#elif DIRECT3D11
	
	#ifndef VERTEX_SURFACE_LIGHT_OMNI
		#define VERTEX_SURFACE_LIGHT_OMNI
		
		struct VERTEX_OUT {
			float4 position : SV_POSITION;
			float4 texcoord_0 : TEXCOORD0;
			float3 texcoord_1 : TEXCOORD1;
			float4 texcoord_2 : TEXCOORD2;
			float4 texcoord_3 : TEXCOORD3;
			float3 texcoord_4 : TEXCOORD4;
			float3 texcoord_5 : TEXCOORD5;
			#ifdef SHADOW
				float4 texcoord_6 : TEXCOORD6;
			#endif
			float4 texcoord_7 : TEXCOORD7;
			float4 texcoord_8 : TEXCOORD8;
			#ifdef FOAM
				float4 texcoord_9 : TEXCOORD9;
			#endif
			#ifdef CAPS
				float4 texcoord_10 : TEXCOORD10;
			#endif
		};
		
		cbuffer shader_light_omni_parameters {
			float4 normal_0_transform;
			float4 normal_1_transform;
			float4 normal_2_transform;
			float4 normal_3_transform;
			#ifdef FOAM
				float4 foam_0_transform;
				float4 foam_1_transform;
			#endif
			#ifdef CAPS
				float4 caps_0_transform;
				float4 caps_1_transform;
			#endif
		};
		
	#else
		
		OUT.position = getPosition(vertex);
		
		OUT.texcoord_0 = float4(texcoord,0.0f,0.0f);
		
		OUT.texcoord_1 = normal;
		
		OUT.texcoord_2 = direction;
		
		OUT.texcoord_3.xyz = getOmniRadius(s_light_position - vertex.xyz) * s_light_iradius.w;
		OUT.texcoord_3.w = s_light_iradius.w * s_light_iradius.w;
		
		OUT.texcoord_4 = -vertex.xyz;
		
		OUT.texcoord_5 = mul3(vertex.xyz - s_light_position,s_light_transform);
		
		#ifdef SHADOW
			float3 shadow_direction = mul3(s_imodelview,vertex.xyz - s_light_shadow_offset);
			OUT.texcoord_6.xyz = shadow_direction * s_light_shadow_depth_range.x;
			OUT.texcoord_6.w = s_light_shadow_depth_range.y;
		#endif
		
		OUT.texcoord_7.xy = texcoord * normal_0_transform.xy + normal_0_transform.zw;
		OUT.texcoord_7.zw = texcoord * normal_1_transform.xy + normal_1_transform.zw;
		OUT.texcoord_8.xy = texcoord * normal_2_transform.xy + normal_2_transform.zw;
		OUT.texcoord_8.zw = texcoord * normal_3_transform.xy + normal_3_transform.zw;
		
		#ifdef FOAM
			OUT.texcoord_9.xy = texcoord * foam_0_transform.xy + foam_0_transform.zw;
			OUT.texcoord_9.zw = texcoord * foam_1_transform.xy + foam_1_transform.zw;
		#endif
		
		#ifdef CAPS
			OUT.texcoord_10.xy = texcoord * caps_0_transform.xy + caps_0_transform.zw;
			OUT.texcoord_10.zw = texcoord * caps_1_transform.xy + caps_1_transform.zw;
		#endif
		
	#endif
	
/******************************************************************************\
*
* Direct3D9
*
\******************************************************************************/

#elif DIRECT3D9
	
	#ifndef VERTEX_SURFACE_LIGHT_OMNI
		#define VERTEX_SURFACE_LIGHT_OMNI
		
		struct VERTEX_OUT {
			float4 position : POSITION;
			float4 texcoord_0 : TEXCOORD0;
			float3 texcoord_1 : TEXCOORD1;
			float4 texcoord_2 : TEXCOORD2;
			float4 texcoord_3 : TEXCOORD3;
			float3 texcoord_4 : TEXCOORD4;
			float3 texcoord_5 : TEXCOORD5;
			#ifdef SHADOW
				float4 texcoord_6 : TEXCOORD6;
			#endif
			float4 texcoord_7 : TEXCOORD7;
		};
		
	#else
		
		OUT.position = getPosition(vertex);
		
		OUT.texcoord_0 = float4(texcoord,0.0f,0.0f);
		
		OUT.texcoord_1 = normal;
		
		OUT.texcoord_2 = direction;
		
		OUT.texcoord_3.xyz = getOmniRadius(s_light_position - vertex.xyz) * s_light_iradius.w;
		OUT.texcoord_3.w = s_light_iradius.w * s_light_iradius.w;
		
		OUT.texcoord_4 = -vertex.xyz;
		
		OUT.texcoord_5 = mul3(vertex.xyz - s_light_position,s_light_transform);
		
		#ifdef SHADOW
			float3 shadow_direction = mul3(s_imodelview,vertex.xyz - s_light_shadow_offset);
			OUT.texcoord_6.xyz = shadow_direction * s_light_shadow_depth_range.x;
			OUT.texcoord_6.w = s_light_shadow_depth_range.y;
		#endif
		
		OUT.texcoord_7 = getProjection(OUT.position);
		
	#endif
	
/******************************************************************************\
*
* PlayStation3
*
\******************************************************************************/

#elif PLAYSTATION3
	
	#ifndef VERTEX_SURFACE_LIGHT_OMNI
		#define VERTEX_SURFACE_LIGHT_OMNI
		
		struct VERTEX_OUT {
			float4 position : POSITION;
			float4 texcoord_0 : TEXCOORD0;
			float3 texcoord_1 : TEXCOORD1;
			float4 texcoord_2 : TEXCOORD2;
			float4 texcoord_3 : TEXCOORD3;
			float3 texcoord_4 : TEXCOORD4;
			float3 texcoord_5 : TEXCOORD5;
			#ifdef SHADOW
				float4 texcoord_6 : TEXCOORD6;
			#endif
			float4 texcoord_7 : TEXCOORD7;
			float4 texcoord_8 : TEXCOORD8;
			float4 texcoord_9 : TEXCOORD9;
		};
		
		uniform float4 normal_0_transform;
		uniform float4 normal_1_transform;
		uniform float4 normal_2_transform;
		uniform float4 normal_3_transform;
		
	#else
		
		OUT.position = getPosition(vertex);
		
		OUT.texcoord_0 = float4(texcoord,0.0f,0.0f);
		
		OUT.texcoord_1 = normal;
		
		OUT.texcoord_2 = direction;
		
		OUT.texcoord_3.xyz = getOmniRadius(s_light_position - vertex.xyz) * s_light_iradius.w;
		OUT.texcoord_3.w = s_light_iradius.w * s_light_iradius.w;
		
		OUT.texcoord_4 = -vertex.xyz;
		
		OUT.texcoord_5 = mul3(vertex.xyz - s_light_position,s_light_transform);
		
		#ifdef SHADOW
			float3 shadow_direction = mul3(s_imodelview,vertex.xyz - s_light_shadow_offset);
			OUT.texcoord_6.xyz = shadow_direction * s_light_shadow_depth_range.x;
			OUT.texcoord_6.w = s_light_shadow_depth_range.y;
		#endif
		
		OUT.texcoord_7.xy = texcoord * normal_0_transform.xy + normal_0_transform.zw;
		OUT.texcoord_7.zw = texcoord * normal_1_transform.xy + normal_1_transform.zw;
		OUT.texcoord_8.xy = texcoord * normal_2_transform.xy + normal_2_transform.zw;
		OUT.texcoord_8.zw = texcoord * normal_3_transform.xy + normal_3_transform.zw;
		
		OUT.texcoord_9 = getProjection(OUT.position);
		
	#endif
	
#endif
